package com.spddr.pmos.cxf;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.ws.rs.PUT;
import javax.ws.rs.Path;

import com.spddr.pmos.jpa.Customer;
import com.spddr.pmos.jpa.TradeWay;

import cn.seqdata.cxf.repos.JaxrsObjectRepository;

@Path("/customer")
public interface JaxrsCustomer extends JaxrsObjectRepository<Customer> {
	@PUT
	@Path("/")
	default <S extends Customer> S save(S entity) {
		Long entity_id = entity.getId();
		if(entity_id != null){
			return getRepository().save(entity);
		}else{
			List<Customer> customers = getRepository().findAll();
			List<Long> ids = new ArrayList<Long>();
			for(Customer customer:customers){
				ids.add(customer.getId());
			}
			Long maxid = Collections.max(ids);
			entity.setId(maxid+1);
			return getRepository().save(entity);
		}
	}
}
